Linux Basics

4 minute read

Table Of Contents

  • Windows file system uses partition, and OS resides in C:
  • Rest of the files can be stored in different partitions as per use cases.
  • In Linux default mode is not to use partitions

Linux File structures

  • Files are ordered in a tree structure starting with root
  • Denoted as / (forward slash)
  • By default directories are /bin, /etc, /tmp, /usr, /home, /root and /var
❗❗❗ Below Section is lifted straight from MongoDB University and Wikipedia and edited/re-arranged for better understanding
  • /etc: Contains the system configuration files for the host computer. You should be careful when making changes to the files contained in this directory.
  • /home: Usually contains users personal data such as your files, notes and user-specific configuration files.
  • /var: The directory name stands for variable, and it is used to store variable files. Files whose content is expected to continually change during normal operation of the system - such as logs and lock files
  • /bin: Essential command binaries that need to be available in single-user mode, including to bring up the system or repair it
  • /lib: Libraries required for /bin and /sbin/
  • /usr: Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications. Should be shareable and read-only

Type of users

Linux is a multi-user Operating Service, where more than one user can use Linux at the same time. There are three types of users.

  • Root: This is the main user account in the Linux system. This user is automatically created during the installation and has the highest privileges in the system. The user can perform any administrative task, and is therefore, also known as superuser or administrator, we usually use sudo (superuser do) command to obtain root privileges
  • Regular User: This is the normal user account with moderate privileges. This user does not have all the privileges of root. For instance, the root user can install new software programs, change the ownership of files, and manage other users’ accounts.
  • Service User: A special user which is used to administer some service (like mail services), this service does not have root privileges for all system, but have some administrative privileges so that they can run their designated services.

Sudo

  • Stands for superuser do.
  • Sudo creates an audit trail
  • Should run command as sudo only when permission with Regular user does not work.

Permissions

There are three kinds of Permissions.

  • Read permission on a file allows the user to view the content of a file.
  • Write permission on a file allows the user to modify the content of that file.
  • Execute permission on a file allows the user to run the file and execute a program or script.

Permission can be changed using chmod command. That syntax of the command can be like chmod ABC file where ABC are read write or execute flags for users.

These flags go like this.

  • First digit is always the owner, AKA the Regular user calling
    • The digit set here, sets permission for the calling user only
  • Second digit is the group, where Regular Calling user is part of.
    • The digit set here, sets permission for all user in the calling user’s group.
  • Third digit is for everyone else (world).
    • The digit set here, sets permission for anyone who can access the system.

The values of digit go like this.

  • 0: No permission
  • 1: Execute only
  • 2: Write only
  • 3: Write and execute (1+2)
  • 4: Read only
  • 5: Read and execute (4+1)
  • 6: Read and write (4+2)
  • 7: Read and write and execute (4+2+1)

Detecting Permission

In the directory run the command ls -la fileName. E.g. Running ls -la dbSecrets.txt may return.

-rwxr--r-- 1 time time timestamp dbSecrets.txt

Here first - suggests it is a file. In case of directory first letter would be d. And file can have read, write and executable permission, - means lack of permission. The permissions of user, group and world are stored in set of 3 letters.

In above example, user who is calling the command has read, write and executable rights. The group of the user has read only right, and world has read only right. The corresponding chmod command would be chmod 744 dbSecrets.txt

Changing ownership

If a user has ownership rights, they can read, write and execute on that file.

Ownership can be changed via chown command. The syntax of the command is chown [new owner]:[group] <file name>.


Course

- M-103     

Tags

- M-103